import java.util.Arrays;

/**
 * 对象数组排序
 */
public class StudentSort {
    public static void main(String[] args) {
        Student[] stus = new Student[5];

        stus[0] = new Student("张三",18,'男');
        stus[1] = new Student("李四",19,'女');
        stus[2] = new Student("王麻子",22,'女');
        stus[3] = new Student("王启年",19,'男');
        stus[4] = new Student("黄蛮儿",10,'男');



        //排序
        for (int i = 0; i < stus.length - 1; i++) {
            for (int j = 0; j < stus.length - 1 - i; j++) {
                if (stus[j].getAge() > stus[j + 1].getAge() ){
                    Student temp = stus[j];
                    stus[j] = stus[j + 1];
                    stus[j+1] = temp;
                } else if (stus[j].getAge() == stus[j + 1].getAge() && stus[j].getGender() > stus[j+1].getGender()) {
                    Student temp = stus[j];
                    stus[j] = stus[j + 1];
                    stus[j+1] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(stus));


    }
}
